package jsu.yym.tiktok.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import jsu.yym.tiktok.pojo.FolderVideoMap;
import jsu.yym.tiktok.pojo.Like;
import jsu.yym.tiktok.pojo.User;
import org.apache.ibatis.annotations.*;
import org.springframework.data.repository.query.Param;

import java.util.List;

@Mapper
public interface FolderVideoMapMapper extends BaseMapper<FolderVideoMap> {

    @Insert("INSERT INTO foldervideomap(file_id, video_id) VALUES (#{file_id}, #{video_id})")
    void insertFolderVideoMap(FolderVideoMap folderVideoMap);

    //根据两个id获取对象
//    FolderVideoMap getVideoMap(@Param("file_id") int file_id, @Param("video_id") int video_id);
    @Select("SELECT video_id FROM foldervideomap WHERE file_id = #{file_id} and video_id = #{video_id}")
    FolderVideoMap getVideoMap(@Param("file_id") int file_id,@Param("video_id") int video_id);

    @Select("SELECT video_id FROM foldervideomap WHERE file_id = #{file_id}")
    List<Integer> getVideoIdByFileId(@Param("file_id") int file_id);

    @Delete("DELETE FROM foldervideomap WHERE file_id = #{file_id} AND video_id = #{video_id}")
    void deleteFolderMapVideo(@Param("file_id") int file_id, @Param("video_id") int video_id);

    // 更新file_id的值
    @Update("update foldervideomap set file_id = #{newFileId} where video_id = #{videoId} and file_id = #{fileId}")
    int updateFileId(@Param("videoId") int videoId, @Param("fileId") int fileId, @Param("newFileId") int newFileId);

    @Select({
            "<script>",
            "SELECT video_id FROM foldervideomap",
            "WHERE file_id IN",
            "<foreach item='file_id' collection='IdList' open='(' separator=',' close=')'>",
            "#{file_id}",
            "</foreach>",
            "</script>"
    })
    List<Integer> getVideoIdByPkIDs(@org.springframework.data.repository.query.Param("IdList") List<Integer> IdList);


}
